import '../utils/TimeUtil.dart';

class UgcData {
  String? ugcId;
  String? title;
  String? content;
  String? goldenLeaves;
  List<String>? imageUrlList;
  String? videoUrl;
  String? videoCover;
  int? state;
  int? mediaSizeType;
  double createTime;
  int? shareNum;
  int? ugcRecUserNum;
  List<UgcRecUser>? ugcRecUserDtoList;
  int? commentNum;
  int? likeNum;
  int? isLike;
  int? isBuy;
  int? followState;
  User? userDto;
  List<Statement>? statementDtoList;
  List<HotComment>? hotCommentDtoList;
  List<Forum>? forumDtoList;
  String get formattedTime => TimeUtil.getTimeAgo(createTime);

  UgcData({
    this.ugcId,
    this.title,
    this.content,
    this.goldenLeaves,
    this.imageUrlList,
    this.videoUrl,
    this.videoCover,
    this.state,
    this.mediaSizeType,
    required this.createTime,
    this.shareNum,
    this.ugcRecUserNum,
    this.ugcRecUserDtoList,
    this.commentNum,
    this.likeNum,
    this.isLike,
    this.isBuy,
    this.followState,
    this.userDto,
    this.statementDtoList,
    this.hotCommentDtoList,
    this.forumDtoList,
  });

  factory UgcData.fromJson(Map<String, dynamic> json) {
    return UgcData(
      ugcId: json['ugcId'],
      title: json['title'],
      content: json['content'],
      goldenLeaves: json['goldenLeaves'],
      imageUrlList:
          (json['imageUrlList'] as List?)?.map((e) => e as String).toList(),
      videoUrl: json['videoUrl'],
      videoCover: json['videoCover'],
      state: json['state'],
      mediaSizeType: json['mediaSizeType'],
      createTime: (json['createTime'] as num?)!.toDouble(),
      shareNum: json['shareNum'],
      ugcRecUserNum: json['ugcRecUserNum'],
      ugcRecUserDtoList: (json['ugcRecUserDtoList'] as List?)
          ?.map((e) => UgcRecUser.fromJson(e))
          .toList(),
      commentNum: json['commentNum'],
      likeNum: json['likeNum'],
      isLike: json['isLike'],
      isBuy: json['isBuy'],
      followState: json['followState'],
      userDto: json['userDto'] != null ? User.fromJson(json['userDto']) : null,
      statementDtoList: (json['statementDtoList'] as List?)
          ?.map((e) => Statement.fromJson(e))
          .toList(),
      hotCommentDtoList: (json['hotCommentDtoList'] as List?)
          ?.map((e) => HotComment.fromJson(e))
          .toList(),
      forumDtoList: (json['forumDtoList'] as List?)
          ?.map((e) => Forum.fromJson(e))
          .toList(),
    );
  }
}

class UgcRecUser {
  String id;
  String nickname;

  UgcRecUser({required this.id, required this.nickname});

  factory UgcRecUser.fromJson(Map<String, dynamic> json) {
    return UgcRecUser(
      id: json['id'],
      nickname: json['nickname'],
    );
  }
}

class User {
  String userId;
  String nickname;
  String avatar;
  String companyName;
  String position;
  String? introduction;

  User(
      {required this.userId,
      required this.nickname,
      required this.avatar,
      required this.companyName,
      required this.position,
      this.introduction});

  factory User.fromJson(Map<String, dynamic> json) {
    return User(
        userId: json['userId'],
        nickname: json['nickname'],
        avatar: json['avatar'],
        companyName: json['companyName'] ?? '',
        position: json['position'] ?? '',
        introduction: json['introduction'] ?? '');
  }
}

class Statement {
  String id;
  String name;
  int isClick;

  Statement({required this.id, required this.name, required this.isClick});

  factory Statement.fromJson(Map<String, dynamic> json) {
    return Statement(
      id: json['id'],
      name: json['name'],
      isClick: json['isClick'],
    );
  }
}

class HotComment {
  String id;
  String userId;
  String content;
  String nickname;
  int isLike;
  int hotValue;
  int likeNum;

  HotComment({
    required this.id,
    required this.userId,
    required this.content,
    required this.nickname,
    required this.isLike,
    required this.hotValue,
    required this.likeNum,
  });

  factory HotComment.fromJson(Map<String, dynamic> json) {
    return HotComment(
      id: json['id'],
      userId: json['userId'],
      content: json['content'],
      nickname: json['nickname'],
      isLike: json['isLike'],
      hotValue: json['hotValue'],
      likeNum: json['likeNum'],
    );
  }
}

class Forum {
  String? forumId;
  String? forumName;

  Forum({this.forumId, this.forumName});

  factory Forum.fromJson(Map<String, dynamic> json) {
    return Forum(
      forumId: json['forumId'],
      forumName: json['forumName'],
    );
  }
}
